PKG_CONFIG ?= pkg-config

# !gmock依赖gtest，无需重复链接
LIBS := gmock_main
ifeq ($(shell $(PKG_CONFIG) --exists $(LIBS) && echo yes), yes)
CXXFLAGS += $(shell $(PKG_CONFIG) --cflags $(LIBS))
LDFLAGS += $(shell $(PKG_CONFIG) --libs $(LIBS))
else
$(error "$(LIBS) not found")
endif

CXXFLAGS += -std=c++17 -g -ggdb -Wall -Werror

# 设置默认目标为最新 .cpp 文件
# 若想编译其他文件，依托makefile的默认规则，直接执行make <file_basename>即可
default := $(shell ls -t *.cpp | head -n1)
target := $(basename $(notdir $(default)))
$(target): $(default)
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $@ $<